The magnetic field may be produced by the planet's two hot spots on the surface. Mercury has a very eccentric orbit. There are two points in its orbit where it is closest to the Sun. At these times, there are two areas that are heated more than any other on the planet. The heat may partially melt conductive material in the outer core. This would create a magnetic field between the hot spots as the planet rotates.
The magnetic field may have been produced when the planet was formed. Long ago, the core of Mercury was definitely liquid. Then, the planet had a much stronger magnetic field. This field may have magnetized the iron in the core.